package com.edu.exam.entity.curriculum.questionbank;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 评分标准实体类
 * 所属模块：B-02 题库管理模块
 * 对应数据库表：grading_standard
 *
 * 根据B-02-03-07简答题管理子模块设计文档实现
 * 管理简答题的评分标准信息，支持多层次评分标准、分级评分和灵活配置。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "grading_standard")
@Comment("评分标准表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class QuestionBankGradingStandard {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 评分标准唯一标识符
     */
    @NotBlank(message = "评分标准ID不能为空")
    @Size(max = 50, message = "评分标准ID长度不能超过50个字符")
    @Column(name = "standard_id", nullable = false, length = 50, unique = true)
    private String standardId;

    /**
     * 关联的简答题ID
     */
    @NotBlank(message = "题目ID不能为空")
    @Column(name = "question_id", nullable = false)
    private String questionId;

    /**
     * 评分标准代码
     */
    @NotBlank(message = "评分标准代码不能为空")
    @Size(max = 32, message = "评分标准代码长度不能超过32个字符")
    @Column(name = "standard_code", nullable = false, length = 32)
    private String standardCode;

    /**
     * 评分标准名称
     */
    @NotBlank(message = "评分标准名称不能为空")
    @Size(max = 200, message = "评分标准名称长度不能超过200个字符")
    @Column(name = "standard_name", nullable = false, length = 200)
    private String standardName;

    /**
     * 评分标准描述
     */
    @Column(name = "description", columnDefinition = "TEXT")
    private String description;

    /**
     * 评分标准类型（OVERALL-整体评分，DETAILED-详细评分，RUBRIC-评分量表，CUSTOM-自定义标准）
     */
    @NotBlank(message = "评分标准类型不能为空")
    @Size(max = 20, message = "评分标准类型长度不能超过20个字符")
    @Column(name = "standard_type", nullable = false, length = 20)
    private String standardType;

    /**
     * 评分标准级别（1-主标准，2-子标准，3-详细标准）
     */
    @NotNull(message = "评分标准级别不能为空")
    @Column(name = "level", nullable = false)
    private Integer level;

    /**
     * 父标准ID（用于层级结构）
     */
    @Size(max = 50, message = "父标准ID长度不能超过50个字符")
    @Column(name = "parent_standard_id", length = 50)
    private String parentStandardId;

    /**
     * 分数范围（如：0-10, 8-10, 6-8等）
     */
    @Size(max = 20, message = "分数范围长度不能超过20个字符")
    @Column(name = "score_range", length = 20)
    private String scoreRange;

    /**
     * 最低分数
     */
    @Column(name = "min_score", precision = 5, scale = 2)
    private BigDecimal minScore;

    /**
     * 最高分数
     */
    @Column(name = "max_score", precision = 5, scale = 2)
    private BigDecimal maxScore;

    /**
     * 等级分数（具体分数值）
     */
    @Column(name = "level_score", precision = 5, scale = 2)
    private BigDecimal levelScore;

    /**
     * 等级描述（如：优秀、良好、中等、及格、不及格）
     */
    @Size(max = 50, message = "等级描述长度不能超过50个字符")
    @Column(name = "level_description", length = 50)
    private String levelDescription;

    /**
     * 详细评分标准说明
     */
    @Column(name = "grading_criteria", columnDefinition = "TEXT")
    private String gradingCriteria;

    /**
     * 评分细则说明
     */
    @Column(name = "grading_rules", columnDefinition = "TEXT")
    private String gradingRules;

    /**
     * 评分指标（JSON格式，包含具体指标和权重）
     */
    @Column(name = "grading_indicators", columnDefinition = "TEXT")
    private String gradingIndicators;

    /**
     * 评分维度定义（JSON格式）
     */
    @Column(name = "grading_dimensions", columnDefinition = "TEXT")
    private String gradingDimensions;

    /**
     * 关键评分要点
     */
    @Column(name = "key_grading_points", columnDefinition = "TEXT")
    private String keyGradingPoints;

    /**
     * 扣分标准（扣分项目和扣分规则）
     */
    @Column(name = "deduction_criteria", columnDefinition = "TEXT")
    private String deductionCriteria;

    /**
     * 加分标准（加分项目和加分规则）
     */
    @Column(name = "bonus_criteria", columnDefinition = "TEXT")
    private String bonusCriteria;

    /**
     * 答案质量要求
     */
    @Column(name = "answer_quality_requirements", columnDefinition = "TEXT")
    private String answerQualityRequirements;

    /**
     * 答案完整性要求
     */
    @Column(name = "completeness_requirements", columnDefinition = "TEXT")
    private String completenessRequirements;

    /**
     * 答案准确性要求
     */
    @Column(name = "accuracy_requirements", columnDefinition = "TEXT")
    private String accuracyRequirements;

    /**
     * 答案创新性要求
     */
    @Column(name = "creativity_requirements", columnDefinition = "TEXT")
    private String creativityRequirements;

    /**
     * 评分示例（典型答案示例和对应评分）
     */
    @Column(name = "grading_examples", columnDefinition = "TEXT")
    private String gradingExamples;

    /**
     * 常见错误和扣分
     */
    @Column(name = "common_errors_deduction", columnDefinition = "TEXT")
    private String commonErrorsDeduction;

    /**
     * 评分权重（相对于总分的权重）
     */
    @Column(name = "grading_weight", precision = 5, scale = 3)
    private BigDecimal gradingWeight;

    /**
     * 是否为默认标准
     */
    @NotNull(message = "默认标准标识不能为空")
    @Column(name = "is_default", nullable = false)
    private Boolean isDefault;

    /**
     * 是否强制执行
     */
    @NotNull(message = "强制执行标识不能为空")
    @Column(name = "is_mandatory", nullable = false)
    private Boolean isMandatory;

    /**
     * 是否支持分级评分
     */
    @NotNull(message = "分级评分设置不能为空")
    @Column(name = "support_level_grading", nullable = false)
    private Boolean supportLevelGrading;

    /**
     * 是否启用智能评分
     */
    @NotNull(message = "智能评分设置不能为空")
    @Column(name = "enable_smart_grading", nullable = false)
    private Boolean enableSmartGrading;

    /**
     * 智能评分配置（JSON格式）
     */
    @Column(name = "smart_grading_config", columnDefinition = "TEXT")
    private String smartGradingConfig;

    /**
     * 适用评分模式
     */
    @Size(max = 100, message = "适用评分模式长度不能超过100个字符")
    @Column(name = "applicable_grading_modes", length = 100)
    private String applicableGradingModes;

    /**
     * 适用难度级别
     */
    @Size(max = 50, message = "适用难度级别长度不能超过50个字符")
    @Column(name = "applicable_difficulty_levels", length = 50)
    private String applicableDifficultyLevels;

    /**
     * 评分标准状态（ACTIVE-激活，INACTIVE-非激活，DEPRECATED-已废弃，DRAFT-草稿）
     */
    @NotBlank(message = "评分标准状态不能为空")
    @Size(max = 20, message = "评分标准状态长度不能超过20个字符")
    @Column(name = "standard_status", nullable = false, length = 20)
    private String standardStatus;

    /**
     * 是否激活
     */
    @NotNull(message = "激活状态不能为空")
    @Column(name = "is_active", nullable = false)
    private Boolean isActive;

    /**
     * 排序顺序
     */
    @NotNull(message = "排序顺序不能为空")
    @Column(name = "sort_order", nullable = false)
    private Integer sortOrder;

    /**
     * 版本号
     */
    @NotNull(message = "版本号不能为空")
    @Column(name = "version_number", nullable = false)
    private Integer versionNumber;

    /**
     * 创建者ID
     */
    @Size(max = 50, message = "创建者ID长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 审核时间
     */
    @Column(name = "review_time")
    private LocalDateTime reviewTime;

    /**
     * 发布时间
     */
    @Column(name = "publish_time")
    private LocalDateTime publishTime;

    /**
     * 软删除标识
     */
    @NotNull(message = "软删除标识不能为空")
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 更新人
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;

    /**
     * 审核者ID
     */
    @Size(max = 50, message = "审核者ID长度不能超过50个字符")
    @Column(name = "reviewed_by", length = 50)
    private String reviewedBy;

    /**
     * 发布者ID
     */
    @Size(max = 50, message = "发布者ID长度不能超过50个字符")
    @Column(name = "published_by", length = 50)
    private String publishedBy;
}